<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>修改页面</title>
    <script type="text/javascript" src="/js/jquery-3.3.1.min.js"></script>
    <script>
        $(function () {

            var exec=true;

            /*发送ajax查看标题是否存在*/
            $("#title").blur(function () {
                var title=$(this).val();
                $.ajax({
                    type:"post",
                    url:"/detail/findByTitle",
                    data:{
                        title:title
                    },
                    dataType:"text",
                    success:function (resp) {
                        if(resp=="meiyou"){
                            $("#message").html("恭喜你这个标题可以用");
                            exec=true;
                        }else {
                            $("#message").html("很抱歉这个标签已经存在了");
                            exec=false;
                        }
                    }
                })
            });

            $("#myForm").submit(function () {
                var title=$("#title").val();
                if (!title){
                    alert("标题不能为空");
                    return false;
                }
                if(!exec){
                    return false;
                }
                return true;
            });

        });
    </script>




</head>

<body>

<form action="/detail/update" method="post" id="myForm">
<table align="center" border="1px solid" width="600px" style="border-collapse: collapse">
    <tr style="background-color: darkgray">
        <td colspan="2" align="center"><h1>更新新闻类容</h1></td>
    </tr>

    <tr>
        <td>新闻编号</td>
        <td>${detail.id}</td>
    </tr>

    <tr>
        <td>新闻分类</td>
        <td>
            <select name="categoryId">
                <c:forEach items="${categoryList}" var="cat">
                <option value="${cat.id}"  <c:if test="${cat.id==detail.categoryId}">selected</c:if>>${cat.name}</option>
                </c:forEach>
            </select>
        </td>
    </tr>

    <tr>
        <td >新闻标题</td>
        <td>
            <input type="text" name="title" id="title" value="${detail.title}">
            <span id="message"></span>
        </td>
    </tr>
    <tr>
        <td>新闻摘要</td>
        <td>   <%--必须写一行--%>
           <textarea name="summary"  rows="5" cols="30">${detail.summary}</textarea>
        </td>
    </tr>
    <tr>
        <td>作者</td>
        <td>
           <input name="author" value="${detail.author}"/>
        </td>
    </tr>

    <tr>
        <td colspan="2" align="center">
            <button type="submit">提交</button><a href="/detail/list"><button id="fanhui" type="button" >返回</button></a>
        </td>
    </tr>
</table>
    <input type="hidden" name="createDate" value="${detail.createDate}" />
    <input type="hidden" name="id" value="${detail.id}">
</form>


</body>
</html>
